package wordnet;

import java.io.File;

import edu.smu.tspell.wordnet.Synset;
import edu.smu.tspell.wordnet.WordNetDatabase;

public class WordNet {
	
	private WordNetDatabase database;	
	
	public WordNet() {
		if(this.database == null) {
			init();
		}
	}
	
	private void init() {
		System.setProperty("wordnet.database.dir", 
				System.getProperty("user.dir")+File.separator+"res"
				+File.separator+"wordnet"+File.separator);
		database = WordNetDatabase.getFileInstance();
	}

	// check if to words have the same meaning (most likely)
	public boolean hasSameMeaning(String input, String compare) {
		Synset[] inputSet = database.getSynsets(input);
		Synset[] compareSet = database.getSynsets(compare);
		for(Synset in : inputSet) {
			for(String inWord :in.getWordForms()) {
				for(Synset comp : compareSet) {
					for(String compWord : comp.getWordForms()) {
						if(compWord.equals(inWord)) {
							return true;
						}
					}
				}
			}
		}
		return false;
	}
}
